﻿using Entity.Blog;
using Entity.Blog.Dto;
using Entity.Blog.Dto.BlogText;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.Blog;
using Service.Finance;

namespace AnQinManagermentBackendAPI.Controller
{
    /// <summary>
    /// 博客正文
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class BlogTextsController : ControllerBase
    {
        /**
         * 业务接口
         */
        private readonly BlogTextService _service;

        /**
         * 构造函数注入
         */
        public BlogTextsController(BlogTextService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(BlogText), 200)]
        public async Task<IActionResult> GetList([FromQuery] BlogTextSearchDto model)
        {
            var response = await _service.GetList(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> Add([FromBody] BlogTextAddDto model)
        {
            var response = await _service.Add(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 修改
        /// </summary>
        [HttpPut]
        public async Task<IActionResult> Put([FromBody] BlogTextUpdateDto model)
        {
            var response = await _service.Put(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> Delete([FromQuery] string Id)
        {
            var response = await _service.Delete(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 阅读
        /// </summary>
        [HttpPost("Read")]
        public async Task<IActionResult> Read(string Id)
        {
            var response = await _service.Read(Id);
            return StatusCode(response.Status, response);
        }
        
        /// <summary>
        /// 打赏
        /// </summary>
        [HttpPost("Reward")]
        public async Task<IActionResult> Reward([FromBody] BlogTextRewardDto model)
        {
            var response = await _service.Reward(model);
            return StatusCode(response.Status, response);
        }


    }
}
